layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form
    layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;

    form.on("submit(addNews)",function(data){
        var formData = new FormData();
        formData.append('title', data.field.title);
        formData.append('content', data.field.content);
        $.ajax({
            type: "post",
            url: baseUrl+"email/insert",
            data: formData,
            async: true,
            processData: false,
            contentType: false,
            success: function(res) {
                if(res.meta.code==200){
                    //加载层
                    var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                    setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 1000);
                    setTimeout(function(){ location.reload() }, 2000);
                }else{
                    //加载层
                    var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                    setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                }
            }
        })
        return false;
    })
})